package 比较器;

import java.util.Arrays;
import java.util.Comparator;

class Student implements Comparable<Student>{
    public int age;
    public String name;
    public double score;

    public Student(int age, String name, double score) {
        this.age = age;
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        return this.age-o.age;
    }
}
class AgeComparator implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }
}
class ScoreComparator implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
        return (int)( o1.score-o2.score);
    }
}
class NameComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}
public class Test {
    public static void sort(Student[]arr){
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if((arr[j].compareTo(arr[j+1]))>0){
                    //根据大小来判断顺序 升序
                    Student tmp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=tmp;
                }
            }
        }

    }
    public static void main(String[] args) {
        Student student=new Student(12,"wzj",78.5);
        Student student1=new Student(32,"wxx",73.4);
        Student student2=new Student(2,"wx",12);
        Student[]arr=new Student[]{student,student1,student2};
        System.out.println(Arrays.toString(arr));
        sort(arr);
        System.out.println(Arrays.toString(arr));
        /*AgeComparator ageComparator=new AgeComparator();
        Arrays.sort(arr,ageComparator);*/
    }
}
